/* eslint-disable @typescript-eslint/explicit-function-return-type */
/*
 * @Author: 高宇 gy15354315043@163.com
 * @Date: 2024-03-27 15:00:02
 * @LastEditors: shiweizhen 787632169@qq.com
 * @LastEditTime: 2025-06-24 11:35:44
 * @Description:
 * Copyright (c) 2024-present HBIS Digital Technology Co.,Ltd. All rights reserved.
 */
import { RouteRecordRaw } from 'vue-router';
import { createRouter, createWebHistory } from 'vue-router';
import { usePermissionStoreHook } from '@/framework/store/modules/permission';
import { constantRoutes } from '@/framework/router';
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const Layout = () => import('@/framework/layout/index.vue');
export const navigationTop = () =>
  import('@/framework/layout/navigationTop.vue');

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
const customRouter: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'dashboard',
    component: () => import('@/views/dashbord/index.vue')
  },
  {
    path: '/univer-sheet',
    name: 'UniverSheet',
    component: () => import('@/views/univer-sheet/index.vue')
  },
  {
    path: '/project',
    name: 'Project',
    component: () => import('@/views/project/index.vue')
  },
  {
    path: '/ag-grid',
    name: 'AgGrid',
    component: () => import('@/views/ag-grid/index.vue')
  }
];
// 静态路由
export const routes: Array<RouteRecordRaw> = [
  ...constantRoutes,
  ...customRouter
];

// 创建路由
const router = createRouter({
  history: createWebHistory(''),
  routes,
  // 刷新时，滚动条位置还原
  scrollBehavior: () => ({ left: 0, top: 0 })
});

// 重置路由
export function resetRouter(): void {
  const permissionStore = usePermissionStoreHook();
  permissionStore.routes.forEach(route => {
    const name = route.name;
    if (name && router.hasRoute(name)) {
      router.removeRoute(name);
    }
  });
}

export default router;
